# 解析 etc下curl.txt 的curl 提取 headers

file_default_path = 'D:\python\code\py-server\etc\curl.txt'


def extract_headers(file_default_path):
    headers = {}
    with open(file_default_path, 'r') as file:
        for line in file:
            if line.strip() == '':
                break  # Stop at the first empty line which separates headers and body
            if '\\' in line:
                key, value = line.split('\\', 1)
                if '-H ' in key:
                    key = key.replace('-H ', '')
                    k, value = key.split(':', 1)
                    k = k.replace("'", '').strip()
                    value = value.replace("'", "").strip()
                    headers[k.strip()] = value.strip()
    return headers


def get_headers(file_path=file_default_path):
    headers = extract_headers(file_path)
    return headers
